# -*- coding: utf-8 -*-

import pygame

# Carga una imagen transparencia y color tranasparente opcionales.
def load_image(filename, transparent=False, pixel=(0,0), alpha=False):
        try: image = pygame.image.load(filename)
        except pygame.error, message:
            raise SystemExit, message
        if alpha:
            image = image.convert_alpha()
        else:
            image = image.convert()
            if transparent:
                color = image.get_at(pixel)
                image.set_colorkey(color, pygame.RLEACCEL)
        return image

def create_text(texto, posx, posy, color=(255, 255, 255), size=14, font=""):
	"Crea un  sprite y su rect de un texto pasado"
	fuente = pygame.font.Font(font, size)
	salida = pygame.font.Font.render(fuente, texto, 1, color)
	salida_rect = salida.get_rect()
	salida_rect.centerx = posx + salida_rect.w / 2
	salida_rect.centery = posy + salida_rect.h / 2
	return salida, salida_rect

# Corta un tilest y lo almacena en un array unidimensional.
def cut_tileset(ruta, (w, h)):
	image = load_image(ruta, alpha=True)
	rect = image.get_rect()
	col = rect.w / w
	fil = rect.h / h
	sprite = [None]

	for f in range(fil):
            for c in range(col):
                sprite.append(image.subsurface((rect.left, rect.top, w, h)))
                rect.left += w
            rect.top += h
            rect.left = 0

	return sprite

def main():
    return 0


if __name__ == '__main__':
    main()